<template>
  <div>
    <form action="" @submit.prevent="update_cate">
      <p>标题：<input type="text" v-model="title"></p>
      <p>链接：<input type="text" v-model="link"></p>
      <p>图片：<input type="file" id="img"></p>
      <p><input type="submit" value="添加"></p>
    </form>
  </div>
</template>
<script>
  import axios from 'axios'

  export default {
    data() {
      return {
        cid: this.$route.params.id,
        title: '',
        link: ''
      }
    },
    methods: {
      update_cate() {
        let new_form = new FormData()
        let file = (document.getElementById('img')).files[0];
        new_form.append('cid', this.cid);
        new_form.append('title', this.title);
        new_form.append('link', this.link);
        new_form.append('img', file, file.name);
        axios({
          url: 'http://127.0.0.1:8000/insertpics/',
          method: 'post',
          data: new_form
        }).then(res => {
          this.$Message(res.data.message)
          window.location.href = '/pics'
        })
      }
    },
  }
</script>
